﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CP.Entities;
using CP.Win.IViews.GPM;
using CP.Repositories.GPM;
using CP.Utility;

namespace CP.Controllers.GPM
{
    public class UserInfoController
    {
        public IUserInfoView View { get; private set; }
        public UserInfoRepository Repository { get; private set; }

        public UserInfoController(IUserInfoView view)
        {
            this.View = view;
            this.Repository = new UserInfoRepository();
            this.View.QuerySubmit += new QueryHandler(View_QuerySubmit);
            this.View.DeleteSubmit += new DeleteUserHandler(View_DeleteSubmit);
        }

        void View_DeleteSubmit(IList<string> users)
        {
            this.Repository.DeleteUserInfo(users);
            QueryUserInfo();
        }

        void View_QuerySubmit()
        {
            QueryUserInfo();
        }

        public void QueryUserInfo()
        {
            IList<User_Info> users = this.Repository.GetAllUsers();
            this.View.BindUserInfo(users);
        }

        public void Initialize()
        {
            QueryUserInfo();
            UserGroupRepository groupRep=new UserGroupRepository();
            IList<User_Group> groups = groupRep.GetAllUserGroups();
            this.View.BindGroupID(groups);

            DepartmentRepository deptRep = new DepartmentRepository();
            IList<Department> depts = deptRep.GetAllDepts();
            this.View.BindDeptID(depts);
        }
    }
}
